package com.guoguo.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.guoguo.base.StaticResource;
import com.guoguo.entity.Attention;
import com.guoguo.entity.UserExt;
import com.guoguo.mapper.InviteRelationMapper;
import com.guoguo.mapper.UserExtMapper;
import com.guoguo.service.IUserExtService;
import com.guoguo.utils.AliOssUtils;
import com.guoguo.utils.RedisUtils;
import com.guoguo.utils.aliOss.AliOssImageConfig;

/**
 * Created by Administrator on 2017/8/9 0009.
 */
@Service
public class UserExtServiceImpl implements IUserExtService {

    //UserExtr接口
    @Autowired
    private UserExtMapper userExtMapper;

    @Autowired
    private InviteRelationMapper inviteRelationMapper;

    @Override
    public UserExt updateUserExt(UserExt userExt) {
        UserExt userExt1=new UserExt();
//        AliOssImageConfig aliOssImageConfig = new AliOssImageConfig("test");
        String icon = AliOssUtils.getImageUrl(userExt1.getIcon());//, aliOssImageConfig);
        userExt1.setIcon(icon);
        int userExts = userExtMapper.updateUserExt(userExt);
        return userExt1;

    }

    public List<UserExt> selectUserExt() {
        return userExtMapper.selectUserExt();
    }

    @Override
    public UserExt findUserExt(String userId) {
        UserExt userExts=userExtMapper.findUserExt(userId);
//        AliOssImageConfig aliOssImageConfig = new AliOssImageConfig("test");
        String icon = AliOssUtils.getImageUrl(userExts.getIcon());//, aliOssImageConfig);
        userExts.setIcon(userExts.getIcon());
        return userExts;
    }


    @Override
    public void insertUserExt(UserExt userExt) {
        userExtMapper.insertUserExt(userExt);
    }

    @Override
    public int updateUserExtJY(String userId) {
        return userExtMapper.updateUserExtJY(userId);

    }

    @Override
    public int updateUserExtQXJY(String userId) {
        return userExtMapper.updateUserExtQXJY(userId);
    }

    @Override
    public void updateUserMember(String rechargeId, int payType, UserExt userExt) {
        RedisUtils redisUtils = RedisUtils.getInstance();
        String payTypeMap = redisUtils.hget(StaticResource.SYS_INIT_RECHARGE_KEY, rechargeId);
        JSONObject rechargeJson = JSONObject.parseObject(payTypeMap);
        userExtMapper.updateUserExt(userExt);
    }

    @Override
    public Attention findUserAttention(Map<String, String> par) {
        return userExtMapper.getUserAttention(par);
    }

    /**
     * @Description： 更新邀请人的积分
     * @author: WYZ
     * @since: 2017年10月25日 下午8:05:33
     */
    @SuppressWarnings("unused")
    @Override
    public Integer addSrcUserPoint(String isScrUser) {
        Integer addCount = null;
        Integer addCountFan = null;
        addCount = userExtMapper.addSrcUserPoint(isScrUser);
        addCountFan = inviteRelationMapper.updateStatus(isScrUser);
        return addCountFan;
    }

}